home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / LGP250S1.ZIP / src / libgplus.5 / libgplus / tests / tgetopt.cc < prev    next >
C/C++ Source or Header  |  1991-06-28  |  1KB  |  66 lines

  1.  
  2. #include <GetOpt.h>
  3.  
  4. int
  5. main (int argc, char **argv)
  6. {
  7.   int digit_optind = 0;
  8.   GetOpt getopt (argc, argv, "abc:d:0123456789");
  9.  
  10.   while (1)
  11.     {
  12.       int this_option_optind = getopt.optind;
  13.       int ch;
  14.       if ((ch = getopt ()) == EOF)
  15.         break;
  16.       char c = char(ch);
  17.       switch (c)
  18.         {
  19.         case '0':
  20.         case '1':
  21.         case '2':
  22.         case '3':
  23.         case '4':
  24.         case '5':
  25.         case '6':
  26.         case '7':
  27.         case '8':
  28.         case '9':
  29.           if (digit_optind != 0 && digit_optind != this_option_optind)
  30.             printf ("digits occur in two different argv-elements.\n");
  31.           digit_optind = this_option_optind;
  32.           printf ("option %c\n", c);
  33.           break;
  34.  
  35.         case 'a':
  36.           printf ("option a\n");
  37.           break;
  38.  
  39.         case 'b':
  40.           printf ("option b\n");
  41.           break;
  42.  
  43.         case 'c':
  44.           printf ("option c with value `%s'\n", getopt.optarg);
  45.           break;
  46.  
  47.         case '?':
  48.           break;
  49.  
  50.         default:
  51.           printf ("?? getopt returned character code 0%o ??\n", c);
  52.         }
  53.     }
  54.  
  55.   if (getopt.optind < argc)
  56.     {
  57.       printf ("non-option ARGV-elements: ");
  58.       while (getopt.optind < argc)
  59.         printf ("%s ", argv[getopt.optind++]);
  60.       printf ("\n");
  61.     }
  62.  
  63.   return 0;
  64. }
  65.  
  66.